package com.aoxon.cargo.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.annotation.SuppressLint;

@SuppressLint("SimpleDateFormat")
public class CurrentTimeUtil {
	/**
	 * 获取当前系统时间转化为字符串
	 * 
	 * @return
	 */
	public static String getCurrentTimeString() {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm");
		return simpleDateFormat.format(new Date());

	}

	/**
	 * 返回一个long类型的时间
	 * 
	 * 数据库保存的是long类型
	 * 
	 * @return
	 */
	public static long getDateLong() {
		System.out.println("CurrentTime.java:");
		System.out.println("得到long类型的时间");
		Date date = new Date();
		long timeLong = date.getTime() / 1000;
		System.out.println("输出long类型时间:" + timeLong);
		return timeLong;
	}

	/**
	 * 先转化为date 再转化为string
	 * 
	 * @param longTime
	 * @return
	 */
	public static String longToString(long longTime) {
		System.out.println("到了CurrentTime.java的 longToString");
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		Date date = new Date(longTime * 1000);
		String stringTime = simpleDateFormat.format(date);
		System.out.println("转化为string的类型：" + stringTime);
		return stringTime;
	}

	/**
	 * 把string类型的时间转化为long类型
	 * 
	 * @param stringTime
	 * @return
	 */
	public static Long stringToLong(String stringTime) {
		System.out.println("CurrentTime.java中的stringToLong,把string转化为long");
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		Date date = null;
		try {
			date = simpleDateFormat.parse(stringTime);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Long longTime = date.getTime() / 1000;
		return longTime;
	}

}